<?php

// only logged in users can add and object
gatekeeper();

elgg_make_sticky_form('resume');

// Get user input.
$name = htmlspecialchars(get_input('name', '', false), ENT_QUOTES, 'UTF-8');
$dob = get_input('dob', '');
$gender = get_input('gender', '');
$email = get_input('email','');
$phone = get_input('phone','');
$address = get_input('address','');
$moredetail = get_input('moredetail', '');

// create new skill object
$personals = elgg_get_entities ( array (
		'type' => 'object',
		'subtype' => "personal",
		'owner_guid' => elgg_get_logged_in_user_guid ()
) );
$count = count ( $personals );
if(isset($count) && $count > 0){
	$personal = $personals[0];
	$action = "update";
} else {
	$personal = new ElggObject();
	$action = "create";
}


$personal->subtype = "personal";
$personal->title = $name;
$personal->dob = $dob;
$personal->gender = $gender;
$personal->email = $email;
$personal->phone = $phone;
$personal->address = $address;
$personal->description = $moredetail;


// owner is logged in user
$personal->owner_guid = elgg_get_logged_in_user_guid();

if($personal->save())
{
	system_message(elgg_echo('resume:OK'));
}



// add to river
add_to_river('river/object/resume/create', $action, elgg_get_logged_in_user_guid(), $personal->guid);

// forward user to a main page
forward($CONFIG->wwwroot . "resumes/" . elgg_get_logged_in_user_entity()->username. "?tab=personal");